#pragma once

#include <vector>
#include <assert.h>
#include "../sequence/common.h"

using namespace std;

namespace testCommon
{
	void testPackSize8()
	{
		vector<QWORD> v;
		v.push_back(12);
		v.push_back(45);
		v.push_back(123);
		BYTE data[3];
		ArrayPacker<BYTE, 8, 3> ap;
		ap.pack<QWORD>(v, data);
		for(size_t i = 0; i < v.size(); i++)
		{
			assert(data[i] == v[i]);
		}
	}

	void testGetSize8()
	{
		vector<QWORD> v;
		v.push_back(23);
		v.push_back(54);
		v.push_back(255);
		BYTE data[3];
		ArrayPacker<BYTE, 8, 3> ap;
		ap.pack<QWORD>(v, data);
		for(size_t i = 0; i < v.size(); i++)
		{
			assert(ap.get(data, i) == v[i]);
		}
	}

	void testSetSize8()
	{
		vector<QWORD> v;
		BYTE data[3] = {0, 0, 0};
		ArrayPacker<BYTE, 8, 3> ap;
		ap.set(data, 0, 43);
		assert(data[0] == 43);
		ap.set(data, 1, 255);
		assert(data[1] == 255);
		ap.set(data, 2, 126);
		assert(data[2] == 126);
	}

	void testPackSize3()
	{
		vector<QWORD> v;
		v.push_back(1);
		v.push_back(2);
		v.push_back(3);
		BYTE data[2];
		ArrayPacker<BYTE, 3, 3> ap;
		ap.pack<QWORD>(v, data);
		assert(data[0] == 209);
		assert((data[1] & 1) == 0);
	}

	void testPackSize3overflow()
	{
		vector<QWORD> v;
		v.push_back(1);
		v.push_back(2);
		v.push_back(7);
		v.push_back(1);
		BYTE data[2];
		ArrayPacker<BYTE, 3, 4> ap;
		ap.pack<QWORD>(v, data);
		assert(data[0] == 209);
		assert(data[1] == 3);
	}

	void testGetSize3()
	{
		vector<QWORD> v;
		v.push_back(3);
		v.push_back(5);
		v.push_back(2);
		BYTE data[2];
		ArrayPacker<BYTE, 3, 3> ap;
		ap.pack<QWORD>(v, data);
		assert(ap.get(data, 0) == v[0]);
		assert(ap.get(data, 1) == v[1]);
		assert(ap.get(data, 2) == v[2]);
	}

	void testSetSize3()
	{
		vector<QWORD> v;
		BYTE data[2];
		ArrayPacker<BYTE, 3, 3> ap;
		BYTE value = 8;
		ap.set(data, 0, value);
		assert(ap.get(data, 0) == (value & 7));
		value = 3;
		ap.set(data, 0, value);
		assert(ap.get(data, 0) == (value & 7));
		value = 5;
		ap.set(data, 1, value);
		assert(ap.get(data, 1) == (value & 7));
	}

	void runtests()
	{
		testPackSize8();
		testGetSize8();
		testSetSize8();
		testPackSize3();
		testPackSize3overflow();
		testGetSize3();
		testSetSize3();
	}
}
